@@include("./common/_menu.js")
@@include("./common/_popWindow.js")
var length = 40;
function item_masonry(){ 
	$('.products-box img').load(function(){ 
		$('.infinite-scroll').masonry({ 
			itemSelector: '.item',
			columnWidth:260,
			gutterWidth:40								
		});		
	});
		
	$('.infinite-scroll').masonry({ 
		itemSelector: '.item',
		columnWidth:260,
		gutterWidth:40								
	});	
}
item_masonry();
$(".infinite-scroll").infinitescroll({
	navSelector: ".recommend-more",
	nextSelector: ".recommend-more a",
	itemSelector: ".item",
	requestUrl: "./lib/recommend.json?type=home&categor_id=1&page=",
	
	loading:{
		img: "images/masonry_loading_1.gif",
		msgText: ' ',
		finishedMsg: '',
		render: function(resData,opts){
			var data = "";
			try{
                var temp = JSON.parse(resData);
                if(temp.code == 200) {
                    if(opts.state.currPage >= temp.data.last_page){
                        opts.state.isFinished = true;
                    }
                    $.each(temp.data.data,function(i,item){
						var price = item.current_price ? item.current_price : item.original_price;
                        var brand = 'Brand ranking:Brand ranking:Brand ranking:Brand ranking:Brand rankingBrand rankingBrand rankingBrand ranking';
						if(brand.length > length){
							brand = brand.slice(0,length) + '...';
						} 
						data += '<div class="products-box item"><a href="'+item.href1+'" class="products-box-img"><span class="img-show"><img src="'+item.cover+'" alt=""></span></a><div class="products-box-tips"><h4><a href="'+item.href2+'" class="descrption">'+item.name+'</a><span></span></h4><div class="tips"><span>'+ brand +'<a>NO.'+item.ranking_rank+'</a></span><a class="price">$'+price+'</a></div></div></div>';  
                    })
                }
            }catch(e){}
            return data;
		},
		finished: function(opts){
			if(opts.state.isFinished){ //结束事件
				$(".recommend-more").remove();
				$("#infscr-loading").hide();
				$(window).unbind('.infscr');
			}
		}	
	},errorCallback:function(res){ 
		console.log(res);
	}
	
},function(newElements){
	var $newElems = $(newElements);
	$('.infinite-scroll').masonry('appended', $newElems, false);
	$newElems.fadeIn();
	item_masonry();
	return;
});

$(".products-content").on("click",".products-box-tips h4 span",function(){
	if($(this).hasClass("hov")){
		$(this).removeClass("hov");
	}else{
		$(this).addClass("hov");
	}
})